package com.wntime.simulator.web;

import com.wntime.simulator.device.DeviceService;
import com.wntime.simulator.web.vo.CloneVo;
import com.wntime.simulator.web.vo.FieldsVo;
import com.wntime.simulator.web.vo.SimulatorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/modbus")
public class SimulatorController {

    @Autowired
    private DeviceService deviceService;
    /**
     * 新建simulator
     * 选择simulator类型：SQL，MODBUS...
     * 启用状态
     */
    @RequestMapping("/create")
    public Object create(@RequestBody SimulatorVo simulator) throws Exception {
        return deviceService.create(simulator.toSimulator(simulator));
    }

    @RequestMapping("/list")
    public Object list() {
        return deviceService.list();
    }

    @RequestMapping("/update/field")
    public Object updateField(@RequestBody FieldsVo fields) {
        return deviceService.updateField(fields.getSimulatorId(),fields.getFields());
    }


    @RequestMapping("/view/field")
    public Object viewField(@RequestBody FieldsVo fields) throws Exception {
        return deviceService.viewField(fields.getSimulatorId());
    }

    @RequestMapping("/delete")
    public Object delete(@RequestBody SimulatorVo simulator) throws Exception {
        return deviceService.delete(simulator);
    }

    @RequestMapping("/checkPort")
    public Object checkPort(@RequestBody SimulatorVo simulator) throws Exception {
        return deviceService.checkPort(simulator);
    }

    @RequestMapping("/stop")
    public Object stop(@RequestBody SimulatorVo simulator) {
        return deviceService.stop(simulator);
    }

    @RequestMapping("/start")
    public Object start(@RequestBody SimulatorVo simulator) {
        return deviceService.start(simulator);
    }

    @RequestMapping("/clone")
    public Object clone(@RequestBody CloneVo clone) {
        return deviceService.cloneSimulator(clone);
    }
}
